//
// Created by 高曦祥 on 2023/11/24.
//
#include "storage/page_pool.h"
#include "page_pool.h"
#include "util/file.h"
#include "util/rw_lock.h"

namespace TinyDB {

PagePool::PagePool(TFile *file, t_uint64 page_size, t_uint32 max_page_num)
: file_(file),
  max_page_num_(max_page_num),
  page_size_(page_size),
  last_page_no_(g_invalid_page_no),
  rw_lock_(new RWLock()) {}

PagePool::~PagePool()
{
  
}

void PagePool::Init()
{
  // 初始化数据文件的最后一个page
  t_uint64 file_size = file_->GetFileSize();
  if (file_size % page_size_) {
    last_page_no_ = file_size / page_size_;
  } else {
    last_page_no_ = file_size / page_size_ - 1;
  }

  // 将文件的offset移动到最后一个page的起始位置
  t_uint64 last_page_offset = last_page_no_ * page_size_ - 1;
  
}

}
